#{extends 'main.html' /}
#{set title:'CoolSoft - Change effort estimation unit' /}

<head>
	<script type='text/javascript'>
    function CheckOther(){
        if (document.getElementById("selEffortUnits").value == "new") {
            document.getElementById("otherContainer").innerHTML = "<input id='txtOther' type='text'/> "
        }
        else 
            document.getElementById("otherContainer").innerHTML = "";
    }
    
    function Post(){
    
        var form = document.createElement("form");
        form.setAttribute("method", "post");
        form.setAttribute("action", "setEffortUnit");
        
        var unitArg = document.createElement("input");
        unitArg.setAttribute("type", "hidden");
        unitArg.setAttribute("name", "effortUnit");
        if (document.getElementById("txtOther") != null) 
            unitArg.setAttribute("value", document.getElementById("txtOther").value);
        else 
            unitArg.setAttribute("value", document.getElementById("selEffortUnits").value);
        form.appendChild(unitArg);
		
        var assocProjectArg = document.createElement("input");
        assocProjectArg.setAttribute("type", "hidden");
        assocProjectArg.setAttribute("name", "projId");
        assocProjectArg.setAttribute("value", document.getElementById("project").value);
        form.appendChild(assocProjectArg);
		
		document.body.appendChild(form); // Not entirely sure if this is necessary
        form.submit();        
    }
	</script>
</head>
<input type="hidden" id="project" value="${currentProject.getEntityId()}">
Change effort estimation unit for project ${currentProject.getEntityId()}: 
<br />
<br />
<select id='selEffortUnits' onchange='CheckOther()'>	
	#{list items:distinctEffortUnits, as:'effortUnit'}}
	<option value='${effortUnit.unit}'>${effortUnit.unit}</option>
	#{/list}
	<option value='new'>Other</option>	
</select>
<br />
<div id="otherContainer"></div>
<input type="button" value="Update" onclick="Post()" />


